package com.logic.modular.act.shop;

import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.modular.act.shop.vo.ShopVo;
import com.logic.modular.game.player.bag.service.BagItemServiceImpl;
import com.logic.modular.game.shop.domain.PlayerShop;
import com.logic.modular.game.shop.service.impl.PlayerShopServiceImpl;
import com.logic.modular.act.gm.GMActionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/shopAct")
@Api(tags = "商品接口")
@Slf4j
public class ShopAction {
    @Resource
    private PlayerShopServiceImpl playerShopService;

    @Resource
    private BagItemServiceImpl bagItemService;

    @ApiOperation("渠道支付")
    @PostMapping("/pay")
    private ResponseResult<?> pay(
            @RequestHeader String token,
            @RequestBody GMActionVo.obtainIOneWIngots playerGet
    ) {
        bagItemService.obtainBagItem(playerGet.getUid(), Long.valueOf(playerGet.getCorePropId()), new BigDecimal(playerGet.getNum()));
        log.info("pay:playerId:{},req{}", JwtUtils.getPlayerId(token), playerGet);
        return ResponseResult.success("ok");
    }

    @ApiOperation("商品列表")
    @PostMapping("/goodsList")
    private ResponseResult<PlayerShop> getGoodsList(
            @RequestHeader String token
    ) {
        return ResponseResult.success(playerShopService.getGoodsList(
                JwtUtils.getPlayerId(token)
        ));
    }

    @PostMapping("/flashEquip")
    @ApiOperation("装备刷新")
    public ResponseResult<PlayerShop> flashEquipPool(
            @RequestHeader String token
    ) {
        return ResponseResult.success(playerShopService.flashEquipPool(
                JwtUtils.getPlayerId(token)
        ));
    }

    @PostMapping("/buy")
    @ApiOperation("购买")
    public ResponseResult<PlayerShop> buy(
            @RequestHeader String token,
            @RequestBody ShopVo.ShopAction.buy buy
    ) {
        return ResponseResult.success(playerShopService.buy(
                JwtUtils.getPlayerId(token),
                buy.getGoodsId().toString(),
                buy.getCount()
        ));
    }
}